// const Mock = require('mockjs')
// const Random =Mock.Random

// var id = Mock.mock('@id')
// var DataList = []
// const count = 10
// const image_uri = 'https://file.wuxuwang.com/news/1632390728520-1629786207311-2021-08-24_142304.png'
/*
{
	"code": 0,
	"message": "success",
	"data": {
		"id": 1,
		"title": "PD-L1/CTLA-4双抗KN046注册临床IND获批准，用于PD-(L)1治疗后进展的非小细胞肺癌",
		"articleType": 0,
		"body": "hello world",
		"sourceUrl": "https://www.wuxuwang.com/zixun/78605309-1c13-11ec-b564-b8599fb66350",
		"source": "戊戌数据",
		"viewCount": 0,
		"startedAt": "1636337448633",
		"weight": 50.00,
		"keyword": "",
		"active": 0,
		"isDelete": 0,
		"createdAt": "1636337448633",
		"updatedAt": "1636337448633",
		"imgUrl": "https://file.wuxuwang.com/news/1632390728520-1629786207311-2021-08-24_142304.png"
	}
}*/
const Mock = require('mockjs')// mockjs 导入依赖模块
var id = Mock.mock('@id')// 得到随机的id,字符串
console.log(Mock.mock('@id'), typeof id)
const Random = Mock.Random
const produceNewsData = function() {
  const articles = []
  for (let i = 0; i < 5; i++) {
    var obj = {
      articleType: 0,
      url: Random.url(),
      title: Random.ctitle(), // Random.ctitle(min,max) 随机产生一个中文标题，长度默认在3-7之间
      content: Random.cparagraph(), // Random.cparagraph(min,max) 随机生成一个中文段落，段落里句子个数默认3-7个
      createdTime: Random.date(), // Random.date() 指定生成的日期字符串格式
      img: Random.image(), // 生成默认图片
      username: Random.cname(), // 生成默认名字
      weight: Random.integer(60, 100),
      viewCount: Random.integer(100, 1000),
      source: '戊戌数据',
      keyword: ''
    }

    articles.push(obj)
  }
  return articles
}

Mock.mock('http://localhost::9527/user/kmyuserinfo', 'get', produceNewsData)
/*
const productionNewsData=function(){
  let articles=[]
for (let i = 0; i < count; i++) {
     let news={
    id: "@id()",
    /*
    title: "@title(5, 10)",
    body: 'hello world',
    sourceUrl: '@url',
    // eslint-disable-next-line no-undef
    articleType: Number | 0 - 1,
    weight: '@integer(1, 3)',
    display_time: '@datetime',
    comment_disabled: true,
    // eslint-disable-next-line no-undef
    viewCount: Number | 1 - 1000,
    image_uri,
    // eslint-disable-next-line no-undef
    keyword: Number | 1 - 10,
    source: '戊戌数据',

    display_time: () => Random.date('yyyy.M.d'),
    content: () => Random.csentence(5, 10),
    platforms: ['a-platform']

     }
     articles.push(news)
     console.log(news)
}
return {
  articles:articles
}

}

Mock.mock('/news/api','post',productionNewsData)
/*
module.exports = [
  {
    url: '/vue-element-admin/article/list',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },

  {
    url: '/vue-element-admin/article/detail',
    type: 'get',
    response: config => {
      const { id } = config.query
      for (const article of List) {
        if (article.id === +id) {
          return {
            code: 20000,
            data: article
          }
        }
      }
    }
  },

  {
    url: '/vue-element-admin/article/pv',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: {
          pvData: [
            { key: 'PC', pv: 1024 },
            { key: 'mobile', pv: 1024 },
            { key: 'ios', pv: 1024 },
            { key: 'android', pv: 1024 }
          ]
        }
      }
    }
  },

  {
    url: '/vue-element-admin/article/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/vue-element-admin/article/update',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]

function pagination(crrentpage, size, list) {
  console.log(list)
  console.log(crrentpage, size)
  return list.slice((crrentpage - 1) * size, crrentpage * size)
}
Mock.mock(new RegExp('/user/list'), 'post', (opts) => {
  // eslint-disable-next-line no-undef
  var list = DataList;
  var pageSize=10;
  var crrentpage = JSON.parse(opts.body).crrentpage
  var total = list.length
  // eslint-disable-next-line no-undef
  list = pagination(crrentpage, pageSize, list)
  return {
    'rows': list
  }
})
*/
